<?php
/**
 * 管理员登录
 * User: 王文凡<787802868@qq.com>
 * Date: 2016/8/11 0011
 * Time: 09:39
 */
namespace Admin\Controller;

use Think\Controller;

class LoginController extends Controller
{
    //管理员登录
    public function index()
    {


        if (IS_POST) {
            $arr = D('Member')->doLogin($_POST);
            if ($arr['state'] == 'success') {
                $this->success($arr['info'], U('Index/index'));
            } else {
                $this->error($arr['info']);
            }
        } else {
            $this->assign('title','系统登录');
            $this->display();
        }
    }

    //退出登录
    public function logout()
    {
        session('tc',null);
        session('_AUTH_LIST_131',null);
        $this->assign('title','系统登录');
        $this->redirect('Login/index');

    }


    //请求通知信息
    public function getMessage()
    {
        if (IS_AJAX) {
            $numbers = M('Inform')->where("is_read=%d", 0)->count();
            $arr = M('Inform')->where("is_read=%d", 0)->order("id DESC")->find();
            if (empty($arr)) {
                $this->ajaxReturn($data['number'] = $numbers);
            } else {
                $arr['number'] = $numbers;
                $this->ajaxReturn($arr);
            }

        }
    }

    //修改密码
    public function updatePwd()
    {
        if (IS_POST) {
            $arr = D('Member')->changePw($_POST);
            if ($arr['state'] == 'success') {
                $this->success($arr['info']);
            } else {
                $this->error($arr['info']);
            }
        }
    }

    //修改昵称
    public function updateNickName()
    {
        $uid = $_SESSION['tc']['uid'];
        $nickname = $_POST['nickname'];
        $arr = M('Member')->where("id=%d", $uid)->save(['nickname' => $nickname]);
        if ($arr) {
            $_SESSION['tc']['nickname'] = $nickname;
            $this->success('修改成功!');
        } else {
            $this->error('修改失败');
        }
    }
    //根据分类id获取订单参数信息
    public function getparma($pid=null){
        if(IS_AJAX){
            $data=M('OrderParameter')->where("cate_pid=%d",$pid)->find();
            if($data){
                $arr['state']='success';
                $arr['info']=$data;
            }else{
                $arr['state']='error';
                $arr['info']='请先设置此分类的订单参数';
            }
            $this->ajaxReturn($arr);
        }
    }

    //根据返工id获取原材料
    public function getdata($fid=null){

          if(IS_AJAX){
              $list=M('Workmaterial')->alias("a")->field("a.*,b.m_name,b.bid_price")
                  ->join("sr_material as b ON a.bracode=b.bracode")->where("a.fid=%d and a.status",[$fid,1])->select();
          $this->ajaxReturn($list);
          }
    }






}